<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>

<head>
    <title>修改管理员</title>
    <link rel="stylesheet" href="../../../backstage/css/x-admin.css" media="all">
    <script src="../../../backstage/lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../backstage/js/x-layui.js" charset="utf-8"></script>
</head>

<body>

<div>
    <div class="z-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="powerId" class="layui-form-label">
                    <span class="x-red">*</span>权限ID
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="powerId" name="powerId" required="" lay-verify="powerId" class="layui-input"
                           maxlength="10" onkeyup="value=this.value.replace(/\D+/g,'')">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>修改该条管理员权限
                </div>
            </div>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>状态
                </label>

                <div class="layui-input-inline" id="state" >
                    <input type="radio"  name="state" value="有效" title="有效"  />
                    <input type="radio"  name="state" value="无效" title="无效" />
                </div>


            </div>

            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>权限
                </label>
                <div class="layui-input-inline">
                    <select id="power" name="power">
                        <option value="">请选择权限</option>
                        <%--<option value="超级管理员">超级管理员</option>--%>
                        <option value="用户管理员">用户管理员</option>
                        <option value="商品管理员">商品管理员</option>
                        <option value="前台门户管理员">前台门户管理员</option>
                        <option value="订单管理员">订单管理员</option>
                        <option value="权限分配管理员">权限分配管理员</option>
                        <option value="会员管理员">会员管理员</option>
                        <option value="系统管理员">系统管理员</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label  class="layui-form-label"></label>
                <%--<button id="edit" class="layui-btn" lay-filter="edit" lay-submit="">修改</button>--%>
                <input id="edit" type="button" class="layui-btn" value="修改">
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">

    layui.use(['form', 'layer'], function() {
        $ = layui.jquery;
        var form = layui.form(),
                layer = layui.layer;

        //自定义验证规则
        form.verify({
                    powerId: function(value){
                        if(value.length<=0){
                            return 'id不能为空';
                        }
                    }
        });



        //修改
        $("#edit").click(function() {
            var powerId = $.trim($("#powerId").val());
            var power = $("#power").val();
            var state= $("#state input:checked").val();
            console.log(powerId);



            $.ajax({
                type: 'POST',
                url: '/power/editPower',
                dataType: "json",
                data: {powerId:powerId,newPower:power,newState:state},
                error: function () {
                    alert("失败");
                },
                success: function (data) {
                    if(data.msg=="修改成功"){
                        alert("修改成功");
                    }else if(data.msg=="不能重复修改"){
                        alert("不能重复修改");
                    }else if(data.msg=="没有该条权限"){
                        alert("没有该条权限！");
                    }
                    location.reload();
                }
            });
        });
    });


</script>
</body>

</html>